package org.dce.screencapturer.objects;

import java.awt.AlphaComposite;
import java.awt.Composite;
import java.awt.Graphics2D;
import java.awt.Insets;

public abstract class PaintAttributes {

	private boolean enabled;
	private int transparency = 0;
	private Composite composite;
	
	public PaintAttributes(){
	}

	
	public PaintAttributes(boolean enabled,int transparency){
		this.enabled = enabled;
		this.transparency = transparency;
	}

	public boolean isEnabled() {
		return enabled;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	public int getTransparency() {
		return transparency;
	}

	public void setTransparency(int transparency) {
		this.transparency = transparency;
	}
	
	public void applyAttributes(Graphics2D g2d){
		if (enabled){

			apply(g2d);
			
			if (transparency != 0){
				composite = g2d.getComposite();
				g2d.setComposite(
					AlphaComposite.getInstance(
						AlphaComposite.SRC_OVER, 
						(1f - transparency/100f)));
			}
		}
	}
	
	public void restore(Graphics2D g2d){
		if (composite != null){
			g2d.setComposite(composite);
			composite = null;
		}
	}

	public abstract void apply(Graphics2D g2d);
	
	public Insets getInsets(){
		return new Insets(0,0,0,0);
	}
}
